m = int(input())
n = int(input())

number = 1
person = 0

if n % 7 == 0:
    n -= 1

while True:
    if number % 7 == 0:
        number += 1
    if number == n:
        break
    number += 1
    person = (person+1) % m

print(person+1)